package tinycloud.gui.action;


import tinycloud.gui.dialog.PreferencesDialog;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.AbstractAction;
import tinycloud.gui.dialog.PreferencesDialog;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author nicolas
 */
public class DeleteDirectoryPreferencesDialogAction extends AbstractAction{

    PreferencesDialog dialog;

    public DeleteDirectoryPreferencesDialogAction(PreferencesDialog dialog) {
        this.dialog = dialog;
    }


    public void actionPerformed(ActionEvent e) {
        if(dialog.list.getSelectedIndex() == -1)
            return;
         Connection c;
        try {
            Class.forName("org.hsqldb.jdbcDriver").newInstance();
            c = DriverManager.getConnection("jdbc:hsqldb:file:tinycloud", "sa", "");
            Statement s = c.createStatement();
            s.executeUpdate("DELETE FROM directories WHERE filename = '"+dialog.list.getSelectedValue()+"'");
            s.executeQuery("SHUTDOWN");
            s.close();
            c.close();
        } catch (Exception ex) {
            System.out.print(ex);
        }
         dialog.listModel.remove(dialog.list.getSelectedIndex());
    }

}
